home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / snip9_91.arc / GETDCWD.C < prev    next >
C/C++ Source or Header  |  1991-09-17  |  1KB  |  65 lines

  1. /*
  2. ** GETDCWD.C - returns the current working directory for a specific drive
  3. **
  4. ** for ZTC/C++ by Bob Jarvis
  5. */
  6.  
  7. #include <dos.h>
  8. #include <stdlib.h>
  9. #include <stdio.h>
  10. #include <ctype.h>
  11.  
  12. char *getdcwd(unsigned int drive)   /* 0 = current, 1 = A, 2 = B, etc */
  13. {
  14.         union REGS regs;
  15.         struct SREGS sregs;
  16.         char *retptr;
  17.  
  18.         retptr = malloc(67);
  19.         if(retptr == NULL)
  20.                 return NULL;
  21.  
  22.         if(drive == 0)    /* figure out which drive is current */
  23.         {
  24.                 dos_getdrive(&drive);
  25.                 drive += 1;
  26.         }
  27.  
  28.         *retptr = (drive-1) + 'A';
  29.         *(retptr+1) = ':';
  30.         *(retptr+2) = '\\';
  31.  
  32.         regs.h.ah = 0x47;
  33.         regs.h.dl = drive;
  34.  
  35. #if SPTR
  36.         sregs.ds = getDS();
  37.         regs.x.si = (unsigned)retptr+3;
  38. #else
  39.         sregs.ds = FP_SEG(retptr);
  40.         regs.x.si = FP_OFF(retptr)+3;
  41. #endif
  42.  
  43.         intdosx(®s, ®s, &sregs);
  44.         if(regs.x.ax == 15)     /* drive number invalid */
  45.         {
  46.                 free(retptr);
  47.                 return NULL;
  48.         }
  49.         else    return retptr;
  50. }
  51.  
  52. main(int argc, char *argv[])
  53. {
  54.         char *curpath;
  55.         unsigned int n;
  56.  
  57.         if(argc > 1)
  58.                 n = (tolower(*argv[1]) - 'a') + 1;
  59.         else    dos_getdrive(&n);
  60.  
  61.         curpath = getdcwd(n);
  62.  
  63.         printf("curpath = '%s'\n", curpath);
  64. }
  65.